home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / gdb35src.zoo / dist-gdb / remote.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-05  |  17.6 KB  |  796 lines

  1. /* Memory-access and commands for inferior process, for GDB.
  2.    Copyright (C)  1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Remote communication protocol.
  21.    All values are encoded in ascii hex digits.
  22.  
  23.     Request        Packet
  24.  
  25.     read registers  g
  26.     reply        XX....X        Each byte of register data
  27.                     is described by two hex digits.
  28.                     Registers are in the internal order
  29.                     for GDB, and the bytes in a register
  30.                     are in the same order the machine uses.
  31.             or ENN        for an error.
  32.  
  33.     write regs    GXX..XX        Each byte of register data
  34.                     is described by two hex digits.
  35.     reply        OK        for success
  36.             ENN        for an error
  37.  
  38.     read mem    mAA..AA,LLLL    AA..AA is address, LLLL is length.
  39.     reply        XX..XX        XX..XX is mem contents
  40.             or ENN        NN is errno
  41.  
  42.     write mem    MAA..AA,LLLL:XX..XX
  43.                     AA..AA is address,
  44.                     LLLL is number of bytes,
  45.                     XX..XX is data
  46.     reply        OK        for success
  47.             ENN        for an error
  48.  
  49.     cont        cAA..AA        AA..AA is address to resume
  50.                     If AA..AA is omitted,
  51.                     resume at same address.
  52.  
  53.     step        sAA..AA        AA..AA is address to resume
  54.                     If AA..AA is omitted,
  55.                     resume at same address.
  56.  
  57.     last signal     ?               Reply the current reason for stopping.
  58.                                         This is the same reply as is generated
  59.                     for step or cont : SAA where AA is the
  60.                     signal number.
  61.  
  62.     There is no immediate reply to step or cont.
  63.     The reply comes when the machine stops.
  64.     It is        SAA        AA is the "signal number"
  65.  
  66.     kill req    k
  67. */
  68.  
  69. #include <stdio.h>
  70. #include "defs.h"
  71. #include "param.h"
  72. #include "frame.h"
  73. #include "inferior.h"
  74.  
  75. #include "wait.h"
  76.  
  77. #ifdef USG
  78. #include <sys/types.h>
  79. #include <fcntl.h>
  80. #endif
  81.  
  82. #include <signal.h>
  83. #include <sys/ioctl.h>
  84. #include <sys/file.h>
  85.  
  86. #ifdef HAVE_TERMIO
  87. #include <termio.h>
  88. #undef TIOCGETP
  89. #define TIOCGETP TCGETA
  90. #undef TIOCSETN
  91. #define TIOCSETN TCSETA
  92. #undef TIOCSETP
  93. #define TIOCSETP TCSETAF
  94. #define TERMINAL struct termio
  95. #else
  96. #include <sgtty.h>
  97. #define TERMINAL struct sgttyb
  98. #endif
  99.  
  100. static int kiodebug;
  101. static int timeout = 5;
  102.  
  103. #if 0
  104. int icache;
  105. #endif
  106.  
  107. /* Descriptor for I/O to remote machine.  Initialize it to -1 so that
  108.    remote_open knows that we don't have a file open when the program
  109.    starts.  */
  110. int remote_desc = -1;
  111.  
  112. #define    PBUFSIZ    400
  113.  
  114. /* Maximum number of bytes to read/write at once.  The value here
  115.    is chosen to fill up a packet (the headers account for the 32).  */
  116. #define MAXBUFBYTES ((PBUFSIZ-32)/2)
  117.  
  118. static void remote_send ();
  119. static void putpkt ();
  120. static void getpkt ();
  121. #if 0
  122. static void dcache_flush ();
  123. #endif
  124.  
  125.  
  126. /* Called when SIGALRM signal sent due to alarm() timeout.  */
  127. #ifndef HAVE_TERMIO
  128. void
  129. remote_timer ()
  130. {
  131.   if (kiodebug)
  132.     printf ("remote_timer called\n");
  133.  
  134.   alarm (timeout);
  135. }
  136. #endif
  137.  
  138. /* Open a connection to a remote debugger.
  139.    NAME is the filename used for communication.  */
  140.  
  141. void
  142. remote_open (name, from_tty)
  143.      char *name;
  144.      int from_tty;
  145. {
  146.   TERMINAL sg;
  147.  
  148.   if (remote_desc >= 0)
  149.     close (remote_desc);
  150.  
  151.   remote_debugging = 0;
  152. #if 0
  153.   dcache_init ();
  154. #endif
  155.  
  156.   remote_desc = open (name, O_RDWR);
  157.   if (remote_desc < 0)
  158.     perror_with_name (name);
  159.  
  160.   ioctl (remote_desc, TIOCGETP, &sg);
  161. #ifdef HAVE_TERMIO
  162.   sg.c_cc[VMIN] = 0;        /* read with timeout.  */
  163.   sg.c_cc[VTIME] = timeout * 10;
  164.   sg.c_lflag &= ~(ICANON | ECHO);
  165. #else
  166.   sg.sg_flags = RAW;
  167. #endif
  168.   ioctl (remote_desc, TIOCSETP, &sg);
  169.  
  170.   if (from_tty)
  171.     printf ("Remote debugging using %s\n", name);
  172.   remote_debugging = 1;
  173.  
  174. #ifndef atarist
  175. #ifndef HAVE_TERMIO
  176. #ifndef NO_SIGINTERRUPT
  177.   /* Cause SIGALRM's to make reads fail.  */
  178.   if (siginterrupt (SIGALRM, 1) != 0)
  179.     perror ("remote_open: error in siginterrupt");
  180. #endif
  181. #endif /* atrist */
  182.  
  183.   /* Set up read timeout timer.  */
  184.   if ((void (*)) signal (SIGALRM, remote_timer) == (void (*)) -1)
  185.     perror ("remote_open: error in signal");
  186. #endif
  187.  
  188.   putpkt ("?");            /* initiate a query from remote machine */
  189. }
  190.  
  191. /* Close the open connection to the remote debugger.
  192.    Use this when you want to detach and do something else
  193.    with your gdb.  */
  194. void
  195. remote_close (from_tty)
  196.      int from_tty;
  197. {
  198.   if (!remote_debugging)
  199.     error ("Can't close remote connection: not debugging remotely.");
  200.   
  201.   close (remote_desc);        /* This should never be called if
  202.                    there isn't something valid in
  203.                    remote_desc.  */
  204.  
  205.   /* Do not try to close remote_desc again, later in the program.  */
  206.   remote_desc = -1;
  207.  
  208.   if (from_tty)
  209.     printf ("Ending remote debugging\n");
  210.  
  211.   remote_debugging = 0;
  212. }
  213.  
  214. /* Convert hex digit A to a number.  */
  215.  
  216. static int
  217. fromhex (a)
  218.      int a;
  219. {
  220.   if (a >= '0' && a <= '9')
  221.     return a - '0';
  222.   else if (a >= 'a' && a <= 'f')
  223.     return a - 'a' + 10;
  224.   else
  225.     error ("Reply contains invalid hex digit");
  226. }
  227.  
  228. /* Convert number NIB to a hex digit.  */
  229.  
  230. static int
  231. tohex (nib)
  232.      int nib;
  233. {
  234.   if (nib < 10)
  235.     return '0'+nib;
  236.   else
  237.     return 'a'+nib-10;
  238. }
  239.  
  240. /* Tell the remote machine to resume.  */
  241.  
  242. int
  243. remote_resume (step, signal)
  244.      int step, signal;
  245. {
  246.   char buf[PBUFSIZ];
  247.  
  248. #if 0
  249.   dcache_flush ();
  250. #endif
  251.  
  252.   strcpy (buf, step ? "s": "c");
  253.  
  254.   putpkt (buf);
  255. }
  256.  
  257. /* Wait until the remote machine stops, then return,
  258.    storing status in STATUS just as `wait' would.  */
  259.  
  260. int
  261. remote_wait (status)
  262.      WAITTYPE *status;
  263. {
  264.   unsigned char buf[PBUFSIZ];
  265.  
  266.   WSETEXIT ((*status), 0);
  267.   getpkt (buf);
  268.   if (buf[0] == 'E')
  269.     error ("Remote failure reply: %s", buf);
  270.   if (buf[0] != 'S')
  271.     error ("Invalid remote reply: %s", buf);
  272.   WSETSTOP ((*status), (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))));
  273. }
  274.  
  275. /* Read the remote registers into the block REGS.  */
  276.  
  277. void
  278. remote_fetch_registers (regs)
  279.      char *regs;
  280. {
  281.   char buf[PBUFSIZ];
  282.   int i;
  283.   char *p;
  284.  
  285.   sprintf (buf, "g");
  286.   remote_send (buf);
  287.  
  288.   /* Reply describes registers byte by byte,
  289.      each byte encoded as two hex characters.  */
  290.  
  291.   p = buf;
  292.   for (i = 0; i < REGISTER_BYTES; i++)
  293.     {
  294.       if (p[0] == 0 || p[1] == 0)
  295.     error ("Remote reply is too short: %s", buf);
  296.       regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
  297.       p += 2;
  298.     }
  299. }
  300.  
  301. /* Store the remote registers from the contents of the block REGS.  */
  302.  
  303. void
  304. remote_store_registers (regs)
  305.      char *regs;
  306. {
  307.   char buf[PBUFSIZ];
  308.   int i;
  309.   char *p;
  310.  
  311.   buf[0] = 'G';
  312.   
  313.   /* Command describes registers byte by byte,
  314.      each byte encoded as two hex characters.  */
  315.  
  316.   p = buf + 1;
  317.   for (i = 0; i < REGISTER_BYTES; i++)
  318.     {
  319.       *p++ = tohex ((regs[i] >> 4) & 0xf);
  320.       *p++ = tohex (regs[i] & 0xf);
  321.     }
  322.   *p = '\0';
  323.  
  324.   remote_send (buf);
  325. }
  326.  
  327. #if 0
  328. /* Read a word from remote address ADDR and return it.
  329.    This goes through the data cache.  */
  330.  
  331. int
  332. remote_fetch_word (addr)
  333.      CORE_ADDR addr;
  334. {
  335.   if (icache)
  336.     {
  337.       extern CORE_ADDR text_start, text_end;
  338.  
  339.       if (addr >= text_start && addr < text_end)
  340.     {
  341.       int buffer;
  342.       xfer_core_file (addr, &buffer, sizeof (int));
  343.       return buffer;
  344.     }
  345.     }
  346.   return dcache_fetch (addr);
  347. }
  348.  
  349. /* Write a word WORD into remote address ADDR.
  350.    This goes through the data cache.  */
  351.  
  352. void
  353. remote_store_word (addr, word)
  354.      CORE_ADDR addr;
  355.      int word;
  356. {
  357.   dcache_poke (addr, word);
  358. }
  359. #else /* not 0 */
  360. void remote_fetch_word (addr)
  361.      CORE_ADDR addr;
  362. {
  363.   error ("Internal error: remote_fetch_word is obsolete.\n");
  364. }
  365. void remote_store_word (addr)
  366.      CORE_ADDR addr;
  367. {
  368.   error ("Internal error: remote_store_word is obsolete.\n");
  369. }
  370. #endif /* not 0 */
  371.  
  372. /* Write memory data directly to the remote machine.
  373.    This does not inform the data cache; the data cache uses this.
  374.    MEMADDR is the address in the remote memory space.
  375.    MYADDR is the address of the buffer in our space.
  376.    LEN is the number of bytes.  */
  377.  
  378. void
  379. remote_write_bytes (memaddr, myaddr, len)
  380.      CORE_ADDR memaddr;
  381.      char *myaddr;
  382.      int len;
  383. {
  384.   char buf[PBUFSIZ];
  385.   int i;
  386.   char *p;
  387.  
  388.   if (len > PBUFSIZ / 2 - 20)
  389.     abort ();
  390.  
  391.   sprintf (buf, "M%x,%x:", memaddr, len);
  392.  
  393.   /* Command describes registers byte by byte,
  394.      each byte encoded as two hex characters.  */
  395.  
  396.   p = buf + strlen (buf);
  397.   for (i = 0; i < len; i++)
  398.     {
  399.       *p++ = tohex ((myaddr[i] >> 4) & 0xf);
  400.       *p++ = tohex (myaddr[i] & 0xf);
  401.     }
  402.   *p = '\0';
  403.  
  404.   remote_send (buf);
  405. }
  406.  
  407. /* Read memory data directly from the remote machine.
  408.    This does not use the data cache; the data cache uses this.
  409.    MEMADDR is the address in the remote memory space.
  410.    MYADDR is the address of the buffer in our space.
  411.    LEN is the number of bytes.  */
  412.  
  413. void
  414. remote_read_bytes (memaddr, myaddr, len)
  415.      CORE_ADDR memaddr;
  416.      char *myaddr;
  417.      int len;
  418. {
  419.   char buf[PBUFSIZ];
  420.   int i;
  421.   char *p;
  422.  
  423.   if (len > PBUFSIZ / 2 - 1)
  424.     abort ();
  425.  
  426.   sprintf (buf, "m%x,%x", memaddr, len);
  427.   remote_send (buf);
  428.  
  429.   /* Reply describes registers byte by byte,
  430.      each byte encoded as two hex characters.  */
  431.  
  432.   p = buf;
  433.   for (i = 0; i < len; i++)
  434.     {
  435.       if (p[0] == 0 || p[1] == 0)
  436.     error ("Remote reply is too short: %s", buf);
  437.       myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
  438.       p += 2;
  439.     }
  440. }
  441.  
  442. /* Read LEN bytes from inferior memory at MEMADDR.  Put the result
  443.    at debugger address MYADDR.  Returns errno value.  */
  444. int
  445. remote_read_inferior_memory(memaddr, myaddr, len)
  446.      CORE_ADDR memaddr;
  447.      char *myaddr;
  448.      int len;
  449. {
  450.   int xfersize;
  451.   while (len > 0)
  452.     {
  453.       if (len > MAXBUFBYTES)
  454.     xfersize = MAXBUFBYTES;
  455.       else
  456.     xfersize = len;
  457.  
  458.       remote_read_bytes (memaddr, myaddr, xfersize);
  459.       memaddr += xfersize;
  460.       myaddr  += xfersize;
  461.       len     -= xfersize;
  462.     }
  463.   return 0; /* no error */
  464. }
  465.  
  466. /* Copy LEN bytes of data from debugger memory at MYADDR
  467.    to inferior's memory at MEMADDR.  Returns errno value.  */
  468. int
  469. remote_write_inferior_memory (memaddr, myaddr, len)
  470.      CORE_ADDR memaddr;
  471.      char *myaddr;
  472.      int len;
  473. {
  474.   int xfersize;
  475.   while (len > 0)
  476.     {
  477.       if (len > MAXBUFBYTES)
  478.     xfersize = MAXBUFBYTES;
  479.       else
  480.     xfersize = len;
  481.       
  482.       remote_write_bytes(memaddr, myaddr, xfersize);
  483.       
  484.       memaddr += xfersize;
  485.       myaddr  += xfersize;
  486.       len     -= xfersize;
  487.     }
  488.   return 0; /* no error */
  489. }
  490.  
  491. /*
  492.  
  493. A debug packet whose contents are <data>
  494. is encapsulated for transmission in the form:
  495.  
  496.     $ <data> # CSUM1 CSUM2
  497.  
  498.     <data> must be ASCII alphanumeric and cannot include characters
  499.     '$' or '#'
  500.  
  501.     CSUM1 and CSUM2 are ascii hex representation of an 8-bit 
  502.     checksum of <data>, the most significant nibble is sent first.
  503.     the hex digits 0-9,a-f are used.
  504.  
  505. Receiver responds with:
  506.  
  507.     +    - if CSUM is correct and ready for next packet
  508.     -    - if CSUM is incorrect
  509.  
  510. */
  511.  
  512. static int
  513. readchar ()
  514. {
  515.   char buf;
  516.  
  517.   buf = '\0';
  518. #ifdef HAVE_TERMIO
  519.   /* termio does the timeout for us.  */
  520.   read (remote_desc, &buf, 1);
  521. #else
  522.   alarm (timeout);
  523.   read (remote_desc, &buf, 1);
  524.   alarm (0);
  525. #endif
  526.  
  527.   return buf & 0x7f;
  528. }
  529.  
  530. /* Send the command in BUF to the remote machine,
  531.    and read the reply into BUF.
  532.    Report an error if we get an error reply.  */
  533.  
  534. static void
  535. remote_send (buf)
  536.      char *buf;
  537. {
  538.   int i;
  539.   putpkt (buf);
  540.   getpkt (buf);
  541.  
  542.   if (buf[0] == 'E')
  543.     error ("Remote failure reply: %s", buf);
  544. }
  545.  
  546. /* Send a packet to the remote machine, with error checking.
  547.    The data of the packet is in BUF.  */
  548.  
  549. static void
  550. putpkt (buf)
  551.      char *buf;
  552. {
  553.   int i;
  554.   unsigned char csum = 0;
  555.   char buf2[500];
  556.   char buf3[1];
  557.   int cnt = strlen (buf);
  558.   char ch;
  559.   char *p;
  560.  
  561.   /* Copy the packet into buffer BUF2, encapsulating it
  562.      and giving it a checksum.  */
  563.  
  564.   p = buf2;
  565.   *p++ = '$';
  566.  
  567.   for (i = 0; i < cnt; i++)
  568.     {
  569.       csum += buf[i];
  570.       *p++ = buf[i];
  571.     }
  572.   *p++ = '#';
  573.   *p++ = tohex ((csum >> 4) & 0xf);
  574.   *p++ = tohex (csum & 0xf);
  575.  
  576.   /* Send it over and over until we get a positive ack.  */
  577.  
  578.   do {
  579.     if (kiodebug)
  580.       {
  581.     *p = '\0';
  582.     printf ("Sending packet: %s (%s)\n", buf2, buf);
  583.       }
  584.     write (remote_desc, buf2, p - buf2);
  585.  
  586.     /* read until either a timeout occurs (\0) or '+' is read */
  587.     do {
  588.       ch = readchar ();
  589.     } while ((ch != '+') && (ch != '\0'));
  590.   } while (ch != '+');
  591. }
  592.  
  593. /* Read a packet from the remote machine, with error checking,
  594.    and store it in BUF.  */
  595.  
  596. static void
  597. getpkt (buf)
  598.      char *buf;
  599. {
  600.   char *bp;
  601.   unsigned char csum;
  602.   int c;
  603.   unsigned char c1, c2;
  604.   extern kiodebug;
  605.  
  606.   /* allow immediate quit while reading from device, it could be hung */
  607.   immediate_quit++;
  608.  
  609.   while (1)
  610.     {
  611.       /* Force csum to be zero here because of possible error retry.  */
  612.       csum = 0;
  613.       
  614.       while ((c = readchar()) != '$');
  615.  
  616.       bp = buf;
  617.       while (1)
  618.     {
  619.       c = readchar ();
  620.       if (c == '#')
  621.         break;
  622.       *bp++ = c;
  623.       csum += c;
  624.     }
  625.       *bp = 0;
  626.  
  627.       c1 = fromhex (readchar ());
  628.       c2 = fromhex (readchar ());
  629.       if ((csum & 0xff) == (c1 << 4) + c2)
  630.     break;
  631.       printf ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
  632.           (c1 << 4) + c2, csum & 0xff, buf);
  633.       write (remote_desc, "-", 1);
  634.     }
  635.  
  636.   immediate_quit--;
  637.  
  638.   write (remote_desc, "+", 1);
  639.  
  640.   if (kiodebug)
  641.     fprintf (stderr,"Packet received :%s\n", buf);
  642. }
  643.  
  644. /* The data cache leads to incorrect results because it doesn't know about
  645.    volatile variables, thus making it impossible to debug functions which
  646.    use hardware registers.  Therefore it is #if 0'd out.  Effect on
  647.    performance is some, for backtraces of functions with a few
  648.    arguments each.  For functions with many arguments, the stack
  649.    frames don't fit in the cache blocks, which makes the cache less
  650.    helpful.  Disabling the cache is a big performance win for fetching
  651.    large structures, because the cache code fetched data in 16-byte
  652.    chunks.  */
  653. #if 0
  654. /* The data cache records all the data read from the remote machine
  655.    since the last time it stopped.
  656.  
  657.    Each cache block holds 16 bytes of data
  658.    starting at a multiple-of-16 address.  */
  659.  
  660. #define DCACHE_SIZE 64        /* Number of cache blocks */
  661.  
  662. struct dcache_block {
  663.     struct dcache_block *next, *last;
  664.     unsigned int addr;    /* Address for which data is recorded.  */
  665.     int data[4];
  666. };
  667.  
  668. struct dcache_block dcache_free, dcache_valid;
  669.  
  670. /* Free all the data cache blocks, thus discarding all cached data.  */ 
  671.  
  672. static void
  673. dcache_flush ()
  674. {
  675.   register struct dcache_block *db;
  676.  
  677.   while ((db = dcache_valid.next) != &dcache_valid)
  678.     {
  679.       remque (db);
  680.       insque (db, &dcache_free);
  681.     }
  682. }
  683.  
  684. /*
  685.  * If addr is present in the dcache, return the address of the block 
  686.  * containing it.
  687.  */
  688.  
  689. struct dcache_block *
  690. dcache_hit (addr)
  691. {
  692.   register struct dcache_block *db;
  693.  
  694.   if (addr & 3)
  695.     abort ();
  696.  
  697.   /* Search all cache blocks for one that is at this address.  */
  698.   db = dcache_valid.next;
  699.   while (db != &dcache_valid)
  700.     {
  701.       if ((addr & 0xfffffff0) == db->addr)
  702.     return db;
  703.       db = db->next;
  704.     }
  705.   return NULL;
  706. }
  707.  
  708. /*  Return the int data at address ADDR in dcache block DC.  */
  709.  
  710. int
  711. dcache_value (db, addr)
  712.      struct dcache_block *db;
  713.      unsigned int addr;
  714. {
  715.   if (addr & 3)
  716.     abort ();
  717.   return (db->data[(addr>>2)&3]);
  718. }
  719.  
  720. /* Get a free cache block, put it on the valid list,
  721.    and return its address.  The caller should store into the block
  722.    the address and data that it describes.  */
  723.  
  724. struct dcache_block *
  725. dcache_alloc ()
  726. {
  727.   register struct dcache_block *db;
  728.  
  729.   if ((db = dcache_free.next) == &dcache_free)
  730.     /* If we can't get one from the free list, take last valid */
  731.     db = dcache_valid.last;
  732.  
  733.   remque (db);
  734.   insque (db, &dcache_valid);
  735.   return (db);
  736. }
  737.  
  738. /* Return the contents of the word at address ADDR in the remote machine,
  739.    using the data cache.  */
  740.  
  741. int
  742. dcache_fetch (addr)
  743.      CORE_ADDR addr;
  744. {
  745.   register struct dcache_block *db;
  746.  
  747.   db = dcache_hit (addr);
  748.   if (db == 0)
  749.     {
  750.       db = dcache_alloc ();
  751.       remote_read_bytes (addr & ~0xf, db->data, 16);
  752.       db->addr = addr & ~0xf;
  753.     }
  754.   return (dcache_value (db, addr));
  755. }
  756.  
  757. /* Write the word at ADDR both in the data cache and in the remote machine.  */
  758.  
  759. dcache_poke (addr, data)
  760.      CORE_ADDR addr;
  761.      int data;
  762. {
  763.   register struct dcache_block *db;
  764.  
  765.   /* First make sure the word is IN the cache.  DB is its cache block.  */
  766.   db = dcache_hit (addr);
  767.   if (db == 0)
  768.     {
  769.       db = dcache_alloc ();
  770.       remote_read_bytes (addr & ~0xf, db->data, 16);
  771.       db->addr = addr & ~0xf;
  772.     }
  773.  
  774.   /* Modify the word in the cache.  */
  775.   db->data[(addr>>2)&3] = data;
  776.  
  777.   /* Send the changed word.  */
  778.   remote_write_bytes (addr, &data, 4);
  779. }
  780.  
  781. /* Initialize the data cache.  */
  782.  
  783. dcache_init ()
  784. {
  785.   register i;
  786.   register struct dcache_block *db;
  787.  
  788.   db = (struct dcache_block *) xmalloc (sizeof (struct dcache_block) * 
  789.                     DCACHE_SIZE);
  790.   dcache_free.next = dcache_free.last = &dcache_free;
  791.   dcache_valid.next = dcache_valid.last = &dcache_valid;
  792.   for (i=0;i<DCACHE_SIZE;i++,db++)
  793.     insque (db, &dcache_free);
  794. }
  795. #endif /* 0 */
  796.